package org.journal.dao;

import java.util.List;

import org.hibernate.Query;
import org.journal.entity.AuthoritiesEntity;
import org.journal.entity.UserEntity;
import org.springframework.stereotype.Repository;

@Repository
public class AuthoritiesDAOImpl extends
		GenericDAOImpl<AuthoritiesEntity, Integer> implements AuthoritiesDAO {

	private static final String GET_USER_AUTHORITIES_NAMED_QUERY = "AuthoritiesEntity.getUserAuthorities";

	public Integer createAuthorities(AuthoritiesEntity authorities) {
		return (Integer) save(authorities);

	}

	public List<AuthoritiesEntity> getUserAuthorities(UserEntity user) {
		Query query = sessionFactory.getCurrentSession().getNamedQuery(
				GET_USER_AUTHORITIES_NAMED_QUERY);
		query.setEntity("userEntity", user);
		return search(query);
	}
}
